package cn.iocoder.yudao.framework.redissonlock.core.keyresolver.impl;

import cn.iocoder.yudao.framework.redissonlock.core.keyresolver.RedissonLockKeyResolver;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 分布式锁 Key 解析器实现
 *
 * @author 徐煜东
 */
@Component
public class DefaultRedissonLockKeyResolver implements RedissonLockKeyResolver {
    @Override
    public String resolve(Object[] args, String annotationKey) {
        if (annotationKey != null && !annotationKey.isEmpty()) {
            return annotationKey;
        }
        if (args == null || args.length == 0) {
            return "default_lock";
        }
        return "default_lock:" + Arrays.hashCode(args);
    }
}
